﻿--[[
   @brief    install path mgr
   @author   maxyao
   @version  1.0
   @date     2019-09-23
--]]

install_path_mgr_control = 
{
    inited = false;
    
    init = function()
        base_utility.log("[install_path_mgr_control]install_path_mgr_control init");
        ierd_tgp.tpf_ui.Require("install_path_mgr\\view.lua");
        local tpfui = base_utility.get_component_adapter("ITpf_ui", "ierd_tgp.tpf_ui.GetTPFUI();");
        tpfui:AddLuaListener(
            ierd_tgp.game_library.CLOSE_MAIN_WND, "install_path_mgr_control.close_wnd");
    end;


    show = function(data)
        base_utility.log("[install_path_mgr_control]show");
        install_path_mgr_view:show(true);
    end;

    close = function(data)
        base_utility.log("[install_path_mgr_control]close");
        install_path_mgr_view:show(false);
    end;

    -- 点击关闭按钮
    on_click_close_btn = function()
        base_utility.mainframe_report("install_path_mgr", "btn_click", "click_close_btn");
        install_path_mgr_view:close(); 
    end;

    -- 点击页面关闭按钮
    on_click_web_close_btn = function(data)
        base_utility.mainframe_report("install_path_mgr", "btn_click", "click_web_close_btn");
        install_path_mgr_view:close(); 
    end;

    -- 自动关闭
    close_wnd = function()
        base_utility.log("[install_path_mgr_control]close_wnd");
        install_path_mgr_view:close(); 
    end;

    -- 处理外部的关闭，（比如alt+f4）
    on_dialog_close = function(event_id, json_str)
        install_path_mgr_control.on_click_close_btn();
    end;


    on_show = function(uilib, ctrl_id)
        base_utility.log("[install_path_mgr_control] on_show install_path_mgr_view tpf");
        install_path_mgr_view:on_show(uilib, ctrl_id);
    end;


    on_web_browser_crash = function()
        install_path_mgr_control.close_wnd();
    end;

    get_path = function(data)
        local gamelib =
            base_utility.get_component_adapter("IGame_library",
            "ierd_tgp.game_library.Get_game_library_adapter();");
        if nil ~= gamelib then

            local dialog_ptr = ui_utility.get_ctrl_ptr_by_id(install_path_mgr_view.dialog_id);
            local wnd = dialog_ptr:GetHwnd();
            local dir_initial_str;
            if data ~= nil and data.initial_path ~= nil then
                dir_initial_str = data.initial_path;
            end;
            local ret = gamelib:get_selected_dir_path(wnd, dir_initial_str);
            if ret == false then
                  base_utility.log(
                  "[install_path_mgr_control]get_selected_dir_path return error!", true);
            end
        end
    end;
};

install_path_mgr_control.init();

